{% extends 'base.html' %}
{% block title %}首页{% endblock %}
{% block content %}

<div class="main_4">
    <div class="main_4_2">
    <div class="all">
        <h3>{{ title }}：</h3>
        <div class="article_add">
           <a href="{% url 'article:article_add' %}"><button type="button">添加文章</button></a>
        </div>
        <br>
    </div>
        {% for article in article_all %}
        <div class="main_4_2_1">
            <div class="pic_1"><img src="{{ article.cover_img.url }}"></div>
            <div class="message">
                <dl>
                    <dt><a href="#">【{{article.sort}}】{{article.title}}</a></dt>
                </dl>
                <div class="time">
                    <span><a href="#">{{article.author }}</a></span>{{article.pub_time}}
                    <span>
                        {% if article.author == request.user or request.user.is_superuser %}
                            <a href="{% url 'article:article_del' pk=article.pk %}" onclick="return confirm('确定要删除吗?')">删除</a>
                            <a href="{% url 'article:article_edit' pk=article.pk %}">编辑</a>
                        {% endif %}
                    </span>
                </div>
                <p class="test"><a href="{% url 'article:article_see' pk=article.pk %}">点击阅读>></a></p>
            </div>
        </div>
        {% endfor %}

        <div class="p10" >
          {# articles.paginator.page_range 这个函数返回包含一个所有页码数的 range 对象 #}
          {# 即 range(1, articles.paginator.num_pages + 1) #}

{##}
{#            {% if article_all.has_previous %}#}
{#              <a href="?page={{ article_all.previous_page_number }}">上一页</a>#}
{#            {% endif %}#}
{##}
{#              {% for page_number in article_all.paginator.page_range %}#}
{#                {% ifequal page_number  article_all.number %}#}
{#                  {{ page_number }}#}
{#                {% else %}#}
{#                  <a href="?page={{ page_number }}">{{ page_number }}</a>#}
{#                {% endifequal %}#}
{#              {% endfor %}#}
{##}
{#            {% if article_all.has_next %}#}
{#              <a href="?page={{ article_all.next_page_number }}">下一页</a>#}
{#            {% endif %}#}



            {% if page_obj.has_previous %}
              <a href="?page={{ page_obj.previous_page_number }}">上一页</a>
            {% endif %}

              {% for page_number in page_obj.paginator.page_range %}
                {% ifequal page_number  page_obj.number %}
                  {{ page_number }}
                {% else %}
                  <a href="?page={{ page_number }}">{{ page_number }}</a>
                {% endifequal %}
              {% endfor %}

            {% if page_obj.has_next %}
              <a href="?page={{ page_obj.next_page_number }}">下一页</a>
            {% endif %}
{#                第{{ page_obj.number }}页，共{{ page_obj.paginator.num_pages }}页。#}
        </div>

    </div>
</div>
{% endblock %}